<!-- eslint-disable vue/no-parsing-error -->
<template>
	<cmDialog v-model="dialogState" modal-title="标准复审申报" model-width="1000px">
		<el-form v-if="baseForm.standardReviewList" ref="baseFormRef" :model="baseForm" :rules="props.isView ? {} : baseRules" label-width="100px">
			<el-tabs v-model="activeName" class="tabs" @tab-click="handleClick">
				<el-tab-pane label="基础信息" name="base">
					<div class="content">
						<el-row>
							<el-col :span="12">
								<el-form-item label="标准名称" style="width: 90%">
									<div style="display: flex; width: 100%">
										<el-input :value="standardInfo?.standardProjectName" disabled />
										<el-button v-if="props.editId == ''" type="primary" style="margin-left: 10px" @click="showStandardListModal = true"
											>查询</el-button
										>
									</div>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="标准编号" style="width: 90%">
									<el-input :value="standardInfo?.standardNumber" disabled />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="主管单位" style="width: 90%">
									<el-input :value="standardInfo?.responsibleOrgName" disabled />
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="项目负责人" style="width: 90%">
									<el-input :value="standardInfo?.projectLeader" disabled />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="发布时间" style="width: 90%">
									<el-input :value="standardInfo?.releaseTime" disabled />
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="联系人" style="width: 90%">
									<el-input :value="standardInfo?.contactName" disabled />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="联系电话" style="width: 90%">
									<el-input :value="standardInfo?.contactTel" disabled />
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="复审类型" style="width: 90%">
									<el-radio-group v-model="baseForm.standardReviewList.reviewType" :disabled="true">
										<el-radio :value="0">复审计划内</el-radio>
										<el-radio :value="1">复审计划外</el-radio>
									</el-radio-group>
								</el-form-item>
							</el-col>
						</el-row>
						<div class="table">
							<div class="table-title">主编单位</div>
							<div class="table-content">
								<el-row>
									<el-col :span="12">
										<el-form-item label="第一主编单位" style="width: 90%">
											<el-input :value="standardInfo?.unitF" disabled />
										</el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="第二主编单位" style="width: 90%">
											<el-input :value="standardInfo?.unitS" disabled />
										</el-form-item>
									</el-col>
								</el-row>
								<el-row>
									<el-col :span="12">
										<el-form-item label="第三主编单位" style="width: 90%">
											<el-input :value="standardInfo?.unitT" disabled />
										</el-form-item>
									</el-col>
								</el-row>
							</div>
						</div>
						<el-row>
							<el-col :span="12">
								<el-form-item label="工作单位" prop="standardReviewList.workUnits" style="width: 90%">
									<el-input v-model="baseForm.standardReviewList.workUnits" :disabled="shenbaoDisabled" />
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="实施时间" style="width: 90%">
									<el-input :value="standardInfo?.implementationTime" disabled />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="12">
								<el-form-item label="联系地址" style="width: 90%">
									<el-input :value="standardInfo?.contactAddress" disabled />
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="联系邮箱" style="width: 90%">
									<el-input :value="standardInfo?.contactEmail" disabled />
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24">
								<el-form-item label="备注" prop="standardReviewList.reviewRemark" style="width: 100%">
									<el-input
										v-model="baseForm.standardReviewList.reviewRemark"
										type="textarea"
										:rows="4"
										style="width: 100%"
										:disabled="shenbaoDisabled"
									/>
								</el-form-item>
							</el-col>
						</el-row>
					</div>
				</el-tab-pane>
				<el-tab-pane label="复审建议表" name="table">
					<div class="content">
						<div class="table">
							<div class="table-title">复审人员信息(至少5个)</div>
							<div class="table-content">
								<el-button v-if="!shenbaoDisabled" type="primary" style="margin-bottom: 10px" @click="showAddReviewPerson = true">新增</el-button>
								<el-table :data="reviewPersonList" style="width: 100%" border>
									<el-table-column type="index" label="序号" width="60" align="center" />
									<el-table-column label="姓名" prop="reviewName" width="80" align="center" />
									<el-table-column label="工作单位" prop="reviewCompany" width="120" align="center" />
									<el-table-column label="从事专业" prop="reviewProfession" align="center" />
									<el-table-column label="职称/职务" prop="reviewTitle" width="100" align="center" />
									<el-table-column label="联系电话" prop="reviewTel" width="120" align="center" />
									<el-table-column v-if="!shenbaoDisabled" label="操作" width="140" align="center" fixed="right">
										<template #default="scope">
											<!-- <el-button type="danger" size="small" @click="handleDeleteReviewPerson(scope.$index)">删除</el-button>
											<el-button type="success" size="small" @click="handleEditReviewPerson(scope.row, scope.$index)">编辑</el-button> -->
											<el-icon
												:size="16"
												color="#1491FF"
												title="编辑"
												style="cursor: pointer; margin: 0 6px"
												@click="handleEditReviewPerson(scope.row, scope.$index)"
											>
												<Edit />
											</el-icon>
											<el-icon
												:size="16"
												color="#f00"
												title="删除"
												style="cursor: pointer; margin: 0 6px"
												@click="handleDeleteReviewPerson(scope.$index)"
											>
												<Delete />
											</el-icon>
										</template>
									</el-table-column>
								</el-table>
							</div>
						</div>
						<div class="table">
							<div class="table-title">标准发布后的实施情况</div>
							<div class="table-content">
								<div class="add-unit" style="margin-top: 0">
									<div class="tit">1、标准历年版本</div>
								</div>
								<el-table :data="baseForm.previousVersions" style="width: 100%" border>
									<el-table-column type="index" label="序号" width="60" align="center" />
									<el-table-column label="标准编号" prop="standardNumber" align="center" />
									<el-table-column label="标准名称" prop="standardProjectName" align="center" />
									<el-table-column label="操作" width="140" align="center" fixed="right">
										<template #default="scope">
											<el-button size="small" @click="standardDetail(scope.row)">查看</el-button>
										</template>
									</el-table-column>
								</el-table>
								<el-form-item
									label="2、宣贯人数及场次"
									prop="standardReviewImplementation.promotersSession"
									label-position="top"
									style="margin-top: 10px"
								>
									<el-row>
										<el-col :span="24">
											<el-radio-group v-model="baseForm.standardReviewImplementation.promotersSession" :disabled="shenbaoDisabled">
												<el-radio v-for="value in promotersSession" :key="value.id" :value="value.code">{{ value.name }}</el-radio>
											</el-radio-group>
										</el-col>
									</el-row>
									<el-row style="width: 100%">
										<el-col :span="24">
											<el-upload
												:action="uploadApi"
												:headers="uploadHeaders"
												:data="upload1Data"
												accept=".pdf"
												:file-list="upload1ShowList"
												:on-preview="handleUploadPdfPreview"
												:on-success="handleUploadSuccess(1)"
												:on-error="handleUploadError(1)"
												:on-remove="handleUploadRemove(1)"
											>
												<el-button type="default" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
											</el-upload>
										</el-col>
									</el-row>
								</el-form-item>
								<el-form-item
									label="3、是否对本标准进行了新闻媒体宣传报道"
									prop="standardReviewImplementation.newsMediaReport"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.newsMediaReport" :disabled="shenbaoDisabled">
											<el-radio value="1">是</el-radio>
											<el-radio value="0">否</el-radio>
										</el-radio-group>
									</div>
									<div style="width: 100%">
										<el-upload
											:action="uploadApi"
											:headers="uploadHeaders"
											:data="upload2Data"
											accept=".pdf"
											:file-list="upload2ShowList"
											:on-preview="handleUploadPdfPreview"
											:on-success="handleUploadSuccess(2)"
											:on-error="handleUploadError(2)"
											:on-remove="handleUploadRemove(2)"
										>
											<el-button type="default" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
										</el-upload>
									</div>
								</el-form-item>
								<el-form-item
									label="4、是否纳入了主管部门宣贯计划"
									prop="standardReviewImplementation.promotionalPlan"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.promotionalPlan" :disabled="shenbaoDisabled">
											<el-radio value="1">是</el-radio>
											<el-radio value="0">否</el-radio>
										</el-radio-group>
									</div>
									<div style="width: 100%">
										<el-upload
											:action="uploadApi"
											:headers="uploadHeaders"
											:data="upload3Data"
											accept=".pdf"
											:file-list="upload3ShowList"
											:on-preview="handleUploadPdfPreview"
											:on-success="handleUploadSuccess(3)"
											:on-error="handleUploadError(3)"
											:on-remove="handleUploadRemove(3)"
										>
											<el-button type="default" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
										</el-upload>
									</div>
								</el-form-item>
								<el-form-item
									label="5、标准是否采用了先进技术或科研成果"
									prop="standardReviewImplementation.adoptTechnology"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.adoptTechnology" :disabled="shenbaoDisabled">
											<el-radio v-for="value in adoptTechnology" :key="value.id" :value="value.code">{{ value.name }}</el-radio>
										</el-radio-group>
									</div>
									<div style="width: 100%">
										<el-upload
											:action="uploadApi"
											:headers="uploadHeaders"
											:data="upload4Data"
											accept=".pdf"
											:file-list="upload4ShowList"
											:on-preview="handleUploadPdfPreview"
											:on-success="handleUploadSuccess(4)"
											:on-error="handleUploadError(4)"
											:on-remove="handleUploadRemove(4)"
										>
											<el-button type="default" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
										</el-upload>
									</div>
								</el-form-item>
								<el-form-item
									label="6、标准是否获得省部级及以上奖项"
									prop="standardReviewImplementation.winningAwards"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.winningAwards" :disabled="shenbaoDisabled">
											<el-radio v-for="value in winningAwards" :key="value.id" :value="value.code">{{ value.name }}</el-radio>
										</el-radio-group>
									</div>
									<div style="width: 100%">
										<el-upload
											:action="uploadApi"
											:headers="uploadHeaders"
											:data="upload5Data"
											accept=".pdf"
											:file-list="upload5ShowList"
											:on-preview="handleUploadPdfPreview"
											:on-success="handleUploadSuccess(5)"
											:on-error="handleUploadError(5)"
											:on-remove="handleUploadRemove(5)"
										>
											<el-button type="default" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
										</el-upload>
									</div>
								</el-form-item>
								<el-form-item
									label="7、标准是否被政策法规文件引用"
									prop="standardReviewImplementation.quotedPolicies"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.quotedPolicies" :disabled="shenbaoDisabled">
											<el-radio value="0">未被引用</el-radio>
											<el-radio value="1">被引用，具体描述</el-radio>
										</el-radio-group>
									</div>
									<el-form-item
										v-if="baseForm.standardReviewImplementation.quotedPolicies == '1'"
										prop="standardReviewImplementation.quotedPoliciesRemark"
										style="width: 100%"
									>
										<div style="width: 100%">
											<el-input
												v-model="baseForm.standardReviewImplementation.quotedPoliciesRemark"
												:rows="3"
												type="textarea"
												placeholder="若被引用，请具体描述"
												maxlength="500"
												show-word-limit
												:disabled="shenbaoDisabled"
											/>
										</div>
									</el-form-item>
									<div style="width: 100%">
										<el-upload
											:action="uploadApi"
											:headers="uploadHeaders"
											:data="upload6Data"
											accept=".pdf"
											:file-list="upload6ShowList"
											:on-preview="handleUploadPdfPreview"
											:on-success="handleUploadSuccess(6)"
											:on-error="handleUploadError(6)"
											:on-remove="handleUploadRemove(6)"
										>
											<el-button type="default" style="margin-top: 10px" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
										</el-upload>
									</div>
								</el-form-item>
								<el-form-item
									label="8、本标准是否被其他标准引用"
									prop="standardReviewImplementation.quotedOtherStandard"
									label-position="top"
									style="margin-top: 10px"
								>
									<el-radio-group v-model="baseForm.standardReviewImplementation.quotedOtherStandard" :disabled="shenbaoDisabled">
										<el-radio value="0">未被引用</el-radio>
										<el-radio value="1">被引用</el-radio>
									</el-radio-group>
									<div style="width: 100%">
										<el-upload
											:action="uploadApi"
											:headers="uploadHeaders"
											:data="upload7Data"
											accept=".pdf"
											:file-list="upload7ShowList"
											:on-preview="handleUploadPdfPreview"
											:on-success="handleUploadSuccess(7)"
											:on-error="handleUploadError(7)"
											:on-remove="handleUploadRemove(7)"
										>
											<el-button type="default" style="margin-top: 10px" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
										</el-upload>
									</div>
								</el-form-item>
								<el-form-item
									label="9、标准执行过程中收到的反馈意见"
									prop="standardReviewImplementation.feedback"
									label-position="top"
									style="margin-top: 10px"
								>
									<el-input
										v-model="baseForm.standardReviewImplementation.feedback"
										:rows="3"
										type="textarea"
										placeholder="请输入标准执行过程中收到的反馈意见"
										maxlength="500"
										show-word-limit
										:disabled="shenbaoDisabled"
									/>
								</el-form-item>
								<el-form-item label="10、与相关政策法规的关系" label-position="top" style="margin-top: 10px">
									<div style="width: 100%">
										<el-form-item
											label="1)相关法律法规、政策规定的更新情况"
											label-position="top"
											prop="standardReviewImplementation.policiesUpdateStatus"
										>
											<el-input
												v-model="baseForm.standardReviewImplementation.policiesUpdateStatus"
												:rows="3"
												type="textarea"
												placeholder="请输入相关法律法规、政策规定的更新情况"
												maxlength="500"
												show-word-limit
												:disabled="shenbaoDisabled"
											/>
										</el-form-item>
									</div>
									<div style="width: 100%">
										<el-form-item
											label="2)标准内容是否符合相关法律法规、政策规定"
											prop="standardReviewImplementation.conformityPolicies"
											label-position="top"
											style="margin-top: 10px"
										>
											<div style="width: 100%">
												<el-radio-group v-model="baseForm.standardReviewImplementation.conformityPolicies" :disabled="shenbaoDisabled">
													<el-radio value="1">是</el-radio>
													<el-radio value="0">否，具体描述</el-radio>
												</el-radio-group>
											</div>
											<el-form-item
												v-if="baseForm.standardReviewImplementation.conformityPolicies == '0'"
												prop="standardReviewImplementation.conformityPoliciesRemark"
												style="width: 100%"
											>
												<div style="width: 100%">
													<el-input
														v-model="baseForm.standardReviewImplementation.conformityPoliciesRemark"
														:rows="3"
														type="textarea"
														placeholder="若不符合，请具体描述"
														maxlength="500"
														show-word-limit
														:disabled="shenbaoDisabled"
													/>
												</div>
											</el-form-item>
										</el-form-item>
									</div>
								</el-form-item>
								<el-form-item label="11、与相关标准的关系" label-position="top" style="margin-top: 10px">
									<div style="width: 100%">
										<el-form-item label="1)相关标准的更新情况" label-position="top" prop="standardReviewImplementation.standardUpdateStatus">
											<el-input
												v-model="baseForm.standardReviewImplementation.standardUpdateStatus"
												:rows="3"
												type="textarea"
												placeholder="请输入相关标准的更新情况"
												maxlength="500"
												show-word-limit
												:disabled="shenbaoDisabled"
											/>
										</el-form-item>
									</div>
									<div style="width: 100%">
										<el-form-item
											label="2)与国家现行工程建设全文强制规范及强制性条文是否存在重复、矛盾或冲突"
											prop="standardReviewImplementation.ruleRepeat"
											label-position="top"
											style="margin-top: 10px"
										>
											<div style="width: 100%">
												<el-radio-group v-model="baseForm.standardReviewImplementation.ruleRepeat" :disabled="shenbaoDisabled">
													<el-radio value="1">是</el-radio>
													<el-radio value="0">否，具体描述</el-radio>
												</el-radio-group>
											</div>
											<el-form-item
												v-if="baseForm.standardReviewImplementation.ruleRepeat == '0'"
												prop="standardReviewImplementation.ruleRepeatRemark"
												style="width: 100%"
											>
												<div style="width: 100%">
													<el-input
														v-model="baseForm.standardReviewImplementation.ruleRepeatRemark"
														:rows="3"
														type="textarea"
														placeholder="若不存在，请具体描述"
														maxlength="500"
														show-word-limit
														:disabled="shenbaoDisabled"
													/>
												</div>
											</el-form-item>
										</el-form-item>
									</div>
									<div style="width: 100%">
										<el-form-item
											label="3)与国家现行推荐性标准是否存在重复、矛盾或冲突"
											prop="standardReviewImplementation.recommendStandardRepeat"
											label-position="top"
											style="margin-top: 10px"
										>
											<div style="width: 100%">
												<el-radio-group v-model="baseForm.standardReviewImplementation.recommendStandardRepeat" :disabled="shenbaoDisabled">
													<el-radio value="1">是</el-radio>
													<el-radio value="0">否，具体描述</el-radio>
												</el-radio-group>
											</div>
											<el-form-item
												v-if="baseForm.standardReviewImplementation.recommendStandardRepeat == '0'"
												prop="standardReviewImplementation.recommendStandardRepeatRemark"
												style="width: 100%"
											>
												<div style="width: 100%">
													<el-input
														v-model="baseForm.standardReviewImplementation.recommendStandardRepeatRemark"
														:rows="3"
														type="textarea"
														placeholder="若不存在,请具体描述"
														maxlength="500"
														show-word-limit
														:disabled="shenbaoDisabled"
													/>
												</div>
											</el-form-item>
										</el-form-item>
									</div>
									<div style="width: 100%">
										<el-form-item
											label="4)标准主要指标是否与国内外先进标准存在差距"
											prop="standardReviewImplementation.standardDifferences"
											label-position="top"
											style="margin-top: 10px"
										>
											<div style="width: 100%">
												<el-radio-group v-model="baseForm.standardReviewImplementation.standardDifferences" :disabled="shenbaoDisabled">
													<el-radio value="1">是</el-radio>
													<el-radio value="0">否，具体描述</el-radio>
												</el-radio-group>
											</div>
											<el-form-item
												v-if="baseForm.standardReviewImplementation.standardDifferences == '0'"
												prop="standardReviewImplementation.standardDifferencesRemark"
												style="width: 100%"
											>
												<div style="width: 100%">
													<el-input
														v-model="baseForm.standardReviewImplementation.standardDifferencesRemark"
														:rows="3"
														type="textarea"
														placeholder="若不存在差距，请具体描述"
														maxlength="500"
														show-word-limit
														:disabled="shenbaoDisabled"
													/>
												</div>
											</el-form-item>
										</el-form-item>
									</div>
								</el-form-item>
								<el-form-item
									label="12、与其他地方标准整合建议"
									prop="standardReviewImplementation.localStandardSuggestion"
									label-position="top"
									style="margin-top: 10px"
								>
									<el-input
										v-model="baseForm.standardReviewImplementation.localStandardSuggestion"
										:rows="3"
										type="textarea"
										placeholder="请输入与其他地方标准整合建议"
										maxlength="500"
										show-word-limit
										:disabled="shenbaoDisabled"
									/>
								</el-form-item>
								<el-form-item
									label="13、拟修订标准的主编单位是否新增、变更、更名"
									prop="standardReviewImplementation.editorUnitChange"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.editorUnitChange" :disabled="shenbaoDisabled">
											<el-radio value="0">否</el-radio>
											<el-radio value="1">是</el-radio>
										</el-radio-group>
									</div>
									<el-form-item
										v-if="baseForm.standardReviewImplementation.editorUnitChange == '1'"
										prop="standardReviewImplementation.editorUnitChangeReason"
										style="width: 100%"
									>
										<div style="width: 100%">
											<el-input
												v-model="baseForm.standardReviewImplementation.editorUnitChangeReason"
												:rows="3"
												type="textarea"
												placeholder="理由:(包括新增主编单位资质能力)"
												maxlength="500"
												show-word-limit
												:disabled="shenbaoDisabled"
											/>
										</div>
									</el-form-item>
								</el-form-item>
								<el-form-item
									label="14、主编单位自审结论"
									prop="standardReviewImplementation.selfReviewConclusion"
									label-position="top"
									style="margin-top: 10px"
								>
									<div style="width: 100%">
										<el-radio-group v-model="baseForm.standardReviewImplementation.selfReviewConclusion" :disabled="shenbaoDisabled">
											<el-radio v-for="value in selfReviewConclusion" :key="value.id" :value="value.code">{{ value.name }}</el-radio>
										</el-radio-group>
									</div>
									<div style="width: 100%">
										<div v-if="baseForm.standardReviewImplementation.selfReviewConclusion == '3'" style="width: 100%">
											<el-upload
												:action="uploadApi"
												:headers="uploadHeaders"
												:data="upload8Data"
												accept=".pdf"
												:file-list="upload8ShowList"
												:on-preview="handleUploadPdfPreview"
												:on-success="handleUploadSuccess(8)"
												:on-error="handleUploadError(8)"
												:on-remove="handleUploadRemove(8)"
											>
												<el-button type="default" style="margin-top: 10px" :disabled="shenbaoDisabled">上传附件(PDF)</el-button>
											</el-upload>
											<div class="el-form-item">
												<div class="el-input">
													<div class="el-form-item__error" style="color: #fff">请上传承诺书</div>
												</div>
											</div>
										</div>
									</div>
								</el-form-item>
								<el-form-item label="自审结论理由" prop="standardReviewImplementation.selfReviewConclusionReason" label-position="top">
									<el-input
										v-model="baseForm.standardReviewImplementation.selfReviewConclusionReason"
										:rows="3"
										type="textarea"
										placeholder="请输入自审结论理由"
										maxlength="500"
										show-word-limit
										:disabled="shenbaoDisabled"
									/>
								</el-form-item>
								<el-form-item label="15、行业主管部门/提出部门审核意见" prop="standardReviewImplementation.reviewComments" label-position="top">
									<el-input
										v-model="baseForm.standardReviewImplementation.reviewComments"
										:rows="3"
										type="textarea"
										placeholder="请输入行业主管部门/提出部门审核意见"
										maxlength="500"
										show-word-limit
										:disabled="shenbaoDisabled"
									/>
								</el-form-item>
							</div>
						</div>
					</div>
				</el-tab-pane>
				<el-tab-pane label="盖章版复审建议表" name="upload">
					<div class="content">
						<el-row>
							<el-col :span="24">
								<el-form-item label="盖章版复审建议表" label-position="top">
									<el-upload
										drag
										:action="uploadApi"
										:headers="uploadHeaders"
										:data="upload9Data"
										accept=".pdf"
										:file-list="upload9ShowList"
										:on-preview="handleUploadPdfPreview"
										:on-success="handleUploadSuccess(9)"
										:on-error="handleUploadError(9)"
										:on-remove="handleUploadRemove(9)"
										:disabled="Number(baseForm.standardReviewList.reviewStage) > 1"
									>
										<el-icon class="el-icon--upload"><upload-filled /></el-icon>
										<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
									</el-upload>
								</el-form-item>
							</el-col>
						</el-row>
					</div>
				</el-tab-pane>
				<el-tab-pane v-if="props.isAudit && resultDetail" label="复审结论" name="result">
					<div class="content">
						<div class="zhuguan">
							<div class="menu">
								<div
									v-for="(item, index) in zhuguanbumen"
									:key="index"
									class="item"
									:class="{ active: zhuguanIndex == index }"
									@click="zhuguanIndex = index"
								>
									{{ item }}
								</div>
							</div>
							<div v-if="zhuguanIndex == 0" class="box">
								<div class="row">
									<div class="label">意见：</div>
									<div v-if="resultDetail.stateF" class="info">{{ reviewResult1.filter(item => item.code === resultDetail.stateF)[0].name }}</div>
								</div>
								<div class="row">
									<div class="label">批复文件：</div>
									<div v-if="resultDetail.fileListF && resultDetail.fileListF.length > 0" class="info">
										<div v-for="file in resultDetail.fileListF" :key="file.id" style="cursor: pointer" @click="handleUploadPdfPreview(file)">
											{{ file.fileRealName }}.{{ file.fileExtName }}
										</div>
									</div>
								</div>
								<div class="row">
									<div class="label">备注说明：</div>
									<div class="info">
										{{ resultDetail.opinionF }}
									</div>
								</div>
								<div class="row">
									<div class="label">是否有管理文件、具体措施：</div>
									<div class="info">
										{{ resultDetail.hasDocumentF == '1' ? '是' : '否' }}
									</div>
								</div>
								<div v-if="resultDetail.hasDocumentF == '1'" class="row">
									<div class="label">具体内容：</div>
									<div class="info">{{ resultDetail.documentContentF }}</div>
								</div>
							</div>
							<div v-if="zhuguanIndex == 1" class="box">
								<div class="row">
									<div class="label">意见：</div>
									<div v-if="resultDetail.stateS" class="info">{{ reviewResult1.filter(item => item.code === resultDetail.stateS)[0].name }}</div>
								</div>
								<div class="row">
									<div class="label">批复文件：</div>
									<div v-if="resultDetail.fileListS && resultDetail.fileListS.length > 0" class="info">
										<div v-for="file in resultDetail.fileListS" :key="file.id" style="cursor: pointer" @click="handleUploadPdfPreview(file)">
											{{ file.fileRealName }}.{{ file.fileExtName }}
										</div>
									</div>
								</div>
								<div class="row">
									<div class="label">备注说明：</div>
									<div class="info">
										{{ resultDetail.opinionS }}
									</div>
								</div>
								<div class="row">
									<div class="label">是否有管理文件、具体措施：</div>
									<div class="info">
										{{ resultDetail.hasDocumentS == '1' ? '是' : '否' }}
									</div>
								</div>
								<div class="row">
									<div class="label">具体内容：</div>
									<div class="info">{{ resultDetail.documentContentS }}</div>
								</div>
							</div>
							<div v-if="zhuguanIndex == 2" class="box">
								<div class="row">
									<div class="label">意见：</div>
									<div v-if="resultDetail.stateT" class="info">{{ reviewResult1.filter(item => item.code === resultDetail.stateT)[0].name }}</div>
								</div>
								<div class="row">
									<div class="label">批复文件：</div>
									<div v-if="resultDetail.fileListT && resultDetail.fileListT.length > 0" class="info">
										<div v-for="file in resultDetail.fileListT" :key="file.id" style="cursor: pointer" @click="handleUploadPdfPreview(file)">
											{{ file.fileRealName }}.{{ file.fileExtName }}
										</div>
									</div>
								</div>
								<div class="row">
									<div class="label">备注说明：</div>
									<div class="info">
										{{ resultDetail.opinionT }}
									</div>
								</div>
								<div class="row">
									<div class="label">是否有管理文件、具体措施：</div>
									<div class="info">
										{{ resultDetail.hasDocumentT == '1' ? '是' : '否' }}
									</div>
								</div>
								<div class="row">
									<div class="label">具体内容：</div>
									<div class="info">{{ resultDetail.documentContentT }}</div>
								</div>
							</div>
						</div>
						<div v-if="resultDetail.expertState" class="box1">
							<div class="title">专家及总站意见</div>
							<div class="box-content">
								<div class="row">
									<div class="label">意见：</div>
									<div class="info">
										{{ reviewResult1.filter(item => item.code === resultDetail.expertState)[0].name }}
									</div>
								</div>
								<div class="row">
									<div class="label">批复文件：</div>
									<div v-if="resultDetail.expertFileList.length > 0" class="info">
										<div v-for="file in resultDetail.expertFileList" :key="file.id" style="cursor: pointer" @click="handleUploadPdfPreview(file)">
											{{ file.fileRealName }}.{{ file.fileExtName }}
										</div>
									</div>
								</div>
								<div class="row">
									<div class="label">备注说明：</div>
									<div class="info">
										{{ resultDetail.expertOpinion }}
									</div>
								</div>
							</div>
						</div>
						<div v-if="resultDetail.zjwState" class="box1">
							<div class="title">住建委意见</div>
							<div class="box-content">
								<div class="row">
									<div class="label">意见：</div>
									<div class="info">
										{{ reviewResult.filter(item => item.code === resultDetail.zjwState)[0].name }}
									</div>
								</div>
								<div class="row">
									<div class="label">批复文件：</div>
									<div v-if="resultDetail.zjwFileList.length > 0" class="info">
										<div v-for="file in resultDetail.zjwFileList" :key="file.id" style="cursor: pointer" @click="handleUploadPdfPreview(file)">
											{{ file.fileRealName }}.{{ file.fileExtName }}
										</div>
									</div>
								</div>
								<div class="row">
									<div class="label">备注说明：</div>
									<div class="info">
										{{ resultDetail.zjwOpinion }}
									</div>
								</div>
							</div>
						</div>
						<div v-if="resultDetail.zjwState" class="box1">
							<div class="title">复审结论</div>
							<div class="box-content">
								<div class="result">{{ reviewResult.filter(item => item.code === resultDetail.remark)[0].name }}</div>
							</div>
						</div>
					</div>
				</el-tab-pane>
			</el-tabs>
		</el-form>
		<template #footer>
			<div class="dialog-foot">
				<el-button v-if="!props.isView && !shenbaoDisabled && props.editId != '' && !props.isAdmin" @click="saveTemp(1)">暂存</el-button>
				<el-button v-if="!props.isView && !shenbaoDisabled && props.editId != '' && !props.isAdmin" type="primary" @click="submitForm(baseFormRef)"
					>提交</el-button
				>
				<el-button v-if="!props.isView && !shenbaoDisabled && props.editId == '' && !props.isAdmin" type="primary" @click="submitSave"
					>保存</el-button
				>
				<el-button v-if="!props.isView && !shenbaoDisabled && props.editId == '' && props.isAdmin" type="primary" @click="submitForm(baseFormRef)"
					>提交</el-button
				>
				<el-button @click="closeModal">关闭</el-button>
			</div>
		</template>
		<standardList v-model="showStandardListModal" @submit-success="getStandardInfo"></standardList>
		<addReviewPerson
			v-model="showAddReviewPerson"
			:review-person-info="reviewPersonInfo"
			@submit-success="submitReviewPerson"
			@close-dialog="closeReviewPersonDialog"
		/>
		<addDialog v-model="showPDialog" :edit-id="sId" :is-view="true" :is-audit="false"></addDialog>
	</cmDialog>
</template>
<script lang="ts" setup>
import { getResult } from '@/api/fushen/audit'
import { getDetail, reviewAdd, reviewSave, reviewUpdate } from '@/api/fushen/declare'
import { filePreviewByName } from '@/api/sys/upload'
import cmDialog from '@/components/cm-dialog/index.vue'
import { AddReview, ReviewPerson, ReviewResult, StandardInfo } from '@/interface/review'
import { useDictionaryStore } from '@/store/modules/dictionary'
import { useUserStore } from '@/store/modules/user'
import type { FormInstance, TabsPaneContext, UploadRawFile } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import { computed, nextTick, reactive, ref, watch } from 'vue'
import addDialog from '../../Sproject/declare/components/addDialog.vue'
import addReviewPerson from '../components/addReviewPerson.vue'
import standardList from '../components/standardList.vue'

const dictionaryStore = useDictionaryStore()
const userStore = useUserStore()

const promotersSession = dictionaryStore.getDictionaryByCode('T008')
const adoptTechnology = dictionaryStore.getDictionaryByCode('T009')
const winningAwards = dictionaryStore.getDictionaryByCode('T010')
const selfReviewConclusion = dictionaryStore.getDictionaryByCode('T0020')
const reviewResult1 = dictionaryStore.getDictionaryByCode('T016')
const reviewResult = dictionaryStore.getDictionaryByCode('T0035')

const props = defineProps({
	modelValue: Boolean,
	editId: {
		type: String,
		default: ''
	},
	isView: Boolean,
	isAudit: {
		type: Boolean,
		default: false
	},
	showAudit: {
		type: Boolean,
		default: false
	},
	info: {
		type: Object as () => StandardInfo,
		default: null
	},
	isAdmin: {
		type: Boolean,
		default: false
	}
})

const emit = defineEmits(['update:modelValue', 'submit-success', 'dialog-cancel'])

const dialogState = computed({
	get: () => props.modelValue,
	set: val => emit('update:modelValue', val)
})

const shenbaoDisabled = computed(
	() => props.isView || (baseForm.value.standardReviewList.reviewStage != '' && baseForm.value.standardReviewList.reviewStage != '0')
)

const activeName = ref('base')
const baseFormRef = ref<FormInstance>()
const baseForm = ref<AddReview>({
	standardReviewList: {
		projectInfoId: '',
		workUnits: '',
		reviewType: 1,
		reviewRemark: '',
		reviewStage: '',
		progressId: ''
	},
	standardReviewPersonList: [] as ReviewPerson[],
	standardReviewImplementation: {
		promotersSession: '1',
		newsMediaReport: '1',
		promotionalPlan: '1',
		adoptTechnology: '1',
		winningAwards: '1',
		quotedPolicies: '1',
		quotedPoliciesRemark: '',
		quotedOtherStandard: '1',
		feedback: '',
		policiesUpdateStatus: '',
		conformityPolicies: '1',
		conformityPoliciesRemark: '',
		standardUpdateStatus: '',
		ruleRepeat: '1',
		ruleRepeatRemark: '',
		recommendStandardRepeat: '1',
		recommendStandardRepeatRemark: '',
		standardDifferences: '1',
		standardDifferencesRemark: '',
		localStandardSuggestion: '',
		editorUnitChange: '0',
		editorUnitChangeReason: '',
		selfReviewConclusion: '2',
		selfReviewConclusionReason: '',
		reviewComments: ''
	},
	promotersSessionList: [],
	newsMediaReportList: [],
	promotionalPlanList: [],
	adoptTechnologyList: [],
	winningAwardsList: [],
	quotedPoliciesList: [],
	quotedOtherStandardList: [],
	reviewRevisedList: [],
	reviewProposalFormList: [],
	previousVersions: []
})
const baseRules = reactive<any>({
	standardReviewList: {
		workUnits: [{ required: true, message: '请输入', trigger: 'blur' }]
	},
	standardReviewImplementation: {
		promotersSession: [{ required: true, message: '请选择', trigger: 'change' }],
		newsMediaReport: [{ required: true, message: '请选择', trigger: 'change' }],
		promotionalPlan: [{ required: true, message: '请选择', trigger: 'change' }],
		adoptTechnology: [{ required: true, message: '请选择', trigger: 'change' }],
		winningAwards: [{ required: true, message: '请选择', trigger: 'change' }],
		quotedPolicies: [{ required: true, message: '请选择', trigger: 'change' }],
		quotedPoliciesRemark: [{ required: true, message: '若被引用，请具体描述', trigger: 'blur' }],
		policiesUpdateStatus: [{ required: true, message: '请输入相关法律法规、政策规定的更新情况', trigger: 'blur' }],
		conformityPolicies: [{ required: true, message: '请选择', trigger: 'change' }],
		conformityPoliciesRemark: [{ required: true, message: '若不符合，请具体描述', trigger: 'blur' }],
		standardUpdateStatus: [{ required: true, message: '请输入相关标准的更新情况', trigger: 'blur' }],
		ruleRepeat: [{ required: true, message: '请选择', trigger: 'change' }],
		ruleRepeatRemark: [{ required: true, message: '若不存在，请具体描述', trigger: 'blur' }],
		recommendStandardRepeat: [{ required: true, message: '请选择', trigger: 'change' }],
		recommendStandardRepeatRemark: [{ required: true, message: '若不存在,请具体描述', trigger: 'blur' }],
		standardDifferences: [{ required: true, message: '请选择', trigger: 'change' }],
		standardDifferencesRemark: [{ required: true, message: '若不存在差距，请具体描述', trigger: 'blur' }],
		localStandardSuggestion: [{ required: true, message: '请输入与其他地方标准整合建议', trigger: 'blur' }],
		editorUnitChange: [{ required: true, message: '请选择', trigger: 'change' }],
		editorUnitChangeReason: [{ required: true, message: '理由:(包括新增主编单位资质能力)', trigger: 'blur' }],
		selfReviewConclusionReason: [{ required: true, message: '请输入自审结论理由', trigger: 'blur' }],
		selfReviewConclusion: [{ required: true, message: '请选择', trigger: 'change' }],
		reviewComments: [{ required: true, message: '请输入行业主管部门/提出部门审核意见', trigger: 'blur' }]
	}
})
const showStandardListModal = ref<boolean>(false)
const standardInfo = ref<StandardInfo | null>(null)
const reviewPersonList = ref<ReviewPerson[]>([])
const showAddReviewPerson = ref<boolean>(false)
const reviewPersonInfo = ref<ReviewPerson | null>({
	reviewName: '',
	reviewCompany: '',
	reviewProfession: '',
	reviewTitle: '',
	reviewTel: '',
	index: -1
})
const showPDialog = ref<boolean>(false)
const sId = ref<string>('')

const uploadApi = `${import.meta.env.MODE === 'development' ? 'http://220.196.89.86:9173' : window.location.protocol + '//' + window.location.host}/JGBStandardWebApi/api/files/upload`
const uploadHeaders = {
	Authorization: userStore.token
}
const upload1Data = {
	extCode: 'PromotersSession',
	remark: '复审建议表-宣贯人数及场次附件'
}
const upload2Data = {
	extCode: 'NewsMediaReport',
	remark: '复审建议表-是否对本标准进行了新闻媒体宣传报道附件'
}
const upload3Data = {
	extCode: 'PromotionalPlan',
	remark: '复审建议表- 是否纳入了主管部门宣贯计划附件'
}
const upload4Data = {
	extCode: 'AdoptTechnology',
	remark: '复审建议表- 标准是否采用了先进技术或科研成果附件'
}
const upload5Data = {
	extCode: 'WinningAwards',
	remark: '复审建议表-标准是否获得省部级及以上奖项附件'
}
const upload6Data = {
	extCode: 'QuotedPolicies',
	remark: '复审建议表-标准是否被政策法规文件引用附件'
}
const upload7Data = {
	extCode: 'QuotedOtherStandard',
	remark: '复审建议表-本标准是否被其他标准引用附件'
}
const upload8Data = {
	extCode: 'ReviewRevised',
	remark: '复审建议表-应予修订'
}
const upload9Data = {
	extCode: 'ReviewProposalForm',
	remark: '盖章版复审建议表'
}

const upload1List = ref([])
const upload1ShowList = ref<UploadRawFile[]>([])
const upload2List = ref([])
const upload2ShowList = ref<UploadRawFile[]>([])
const upload3List = ref([])
const upload3ShowList = ref<UploadRawFile[]>([])
const upload4List = ref([])
const upload4ShowList = ref<UploadRawFile[]>([])
const upload5List = ref([])
const upload5ShowList = ref<UploadRawFile[]>([])
const upload6List = ref([])
const upload6ShowList = ref<UploadRawFile[]>([])
const upload7List = ref([])
const upload7ShowList = ref<UploadRawFile[]>([])
const upload8List = ref([])
const upload8ShowList = ref<UploadRawFile[]>([])
const upload9List = ref([])
const upload9ShowList = ref<UploadRawFile[]>([])

const resultDetail = ref<ReviewResult>(null)
// eslint-disable-next-line vue/return-in-computed-property
const zhuguanbumen = computed(() => {
	if (resultDetail.value) {
		if (resultDetail.value.stateS != null && resultDetail.value.stateT != null) {
			return ['主管部门1意见', '主管部门2意见', '主管部门3意见']
		}
		if (resultDetail.value.stateS != null) {
			return ['主管部门1意见', '主管部门2意见']
		}
		return ['主管部门意见']
	}
})
const zhuguanIndex = ref(0)

// watch(
// 	() => props.info,
// 	newVal => {
// 		if (newVal) {
// 			standardInfo.value = newVal
// 		}
// 	}
// )

watch(
	() => props.editId,
	newVal => {
		if (newVal) {
			getDtail()
			if (props.isAudit) {
				getResultDetail()
			}
		} else {
			baseFormRef.value?.resetFields()
			upload1List.value = []
			upload1ShowList.value = []
			upload2List.value = []
			upload2ShowList.value = []
			upload3List.value = []
			upload3ShowList.value = []
			upload4List.value = []
			upload4ShowList.value = []
			upload5List.value = []
			upload5ShowList.value = []
			upload6List.value = []
			upload6ShowList.value = []
			upload7List.value = []
			upload7ShowList.value = []
			upload8List.value = []
			upload8ShowList.value = []
			upload9List.value = []
			upload9ShowList.value = []
			reviewPersonList.value = []
			baseForm.value.standardReviewList = {
				projectInfoId: '',
				workUnits: '',
				reviewType: 1,
				reviewRemark: '',
				reviewStage: '',
				progressId: ''
			}
			baseForm.value.standardReviewPersonList = []
			baseForm.value.standardReviewImplementation = {
				promotersSession: '1',
				newsMediaReport: '1',
				promotionalPlan: '1',
				adoptTechnology: '1',
				winningAwards: '1',
				quotedPolicies: '1',
				quotedPoliciesRemark: '',
				quotedOtherStandard: '1',
				feedback: '',
				policiesUpdateStatus: '',
				conformityPolicies: '1',
				conformityPoliciesRemark: '',
				standardUpdateStatus: '',
				ruleRepeat: '1',
				ruleRepeatRemark: '',
				recommendStandardRepeat: '1',
				recommendStandardRepeatRemark: '',
				standardDifferences: '1',
				standardDifferencesRemark: '',
				localStandardSuggestion: '',
				editorUnitChange: '0',
				editorUnitChangeReason: '',
				selfReviewConclusion: '2',
				selfReviewConclusionReason: '',
				reviewComments: ''
			}
			baseForm.value.promotersSessionList = []
			baseForm.value.newsMediaReportList = []
			baseForm.value.promotionalPlanList = []
			baseForm.value.adoptTechnologyList = []
			baseForm.value.winningAwardsList = []
			baseForm.value.quotedPoliciesList = []
			baseForm.value.quotedOtherStandardList = []
			baseForm.value.reviewRevisedList = []
			baseForm.value.reviewProposalFormList = []
		}
	}
)

watch(
	() => props.modelValue,
	newVal => {
		if (!newVal) {
			activeName.value = 'base'
			standardInfo.value = null
		}
	}
)

watch(
	() => showPDialog.value,
	newVal => {
		if (newVal == false) {
			sId.value = ''
		}
	}
)

const getDtail = () => {
	getDetail({
		id: props.editId
	}).then(res => {
		let data = res.data
		standardInfo.value = data.standardProjectInfo
		baseForm.value.standardReviewList = data.standardReviewList
		// baseForm.value.standardReviewPersonList = data.reviewPersonList
		if (data.standardReviewImplementation) {
			baseForm.value.standardReviewImplementation = data.standardReviewImplementation
		}
		baseForm.value.promotersSessionList = data.promotersSessionFileList
		baseForm.value.newsMediaReportList = data.newsMediaReportFileList
		baseForm.value.promotionalPlanList = data.promotionalPlanFileList
		baseForm.value.adoptTechnologyList = data.adoptTechnologyList
		baseForm.value.winningAwardsList = data.winningAwardsFileList
		baseForm.value.quotedPoliciesList = data.quotedPoliciesFileList
		baseForm.value.quotedOtherStandardList = data.quotedOtherStandardFileList
		baseForm.value.reviewRevisedList = data.reviewRevisedFileList
		baseForm.value.reviewProposalFormList = data.reviewProposalFormFileList
		baseForm.value.previousVersions = data.previousVersions
		reviewPersonList.value = []
		if (data.reviewPersonList) {
			data.reviewPersonList.forEach((i: any, index: number) => {
				reviewPersonList.value.push({
					id: i.id,
					reviewName: i.reviewName,
					reviewCompany: i.reviewCompany,
					reviewProfession: i.reviewProfession,
					reviewTitle: i.reviewTitle,
					reviewTel: i.reviewTel,
					index: index
				})
			})
		}
		upload1List.value = data.promotersSessionFileList
		upload1ShowList.value = JSON.parse(JSON.stringify(upload1List.value))
		if (upload1ShowList.value.length > 0) {
			upload1ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload2List.value = data.newsMediaReportFileList
		upload2ShowList.value = JSON.parse(JSON.stringify(upload2List.value))
		if (upload2ShowList.value.length > 0) {
			upload2ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload3List.value = data.promotionalPlanFileList
		upload3ShowList.value = JSON.parse(JSON.stringify(upload3List.value))
		if (upload3ShowList.value.length > 0) {
			upload3ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload4List.value = data.adoptTechnologyList
		upload4ShowList.value = JSON.parse(JSON.stringify(upload4List.value))
		if (upload4ShowList.value.length > 0) {
			upload4ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload5List.value = data.winningAwardsFileList
		upload5ShowList.value = JSON.parse(JSON.stringify(upload5List.value))
		if (upload5ShowList.value.length > 0) {
			upload5ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload6List.value = data.quotedPoliciesFileList
		upload6ShowList.value = JSON.parse(JSON.stringify(upload6List.value))
		if (upload6ShowList.value.length > 0) {
			upload6ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload7List.value = data.quotedOtherStandardFileList
		upload7ShowList.value = JSON.parse(JSON.stringify(upload7List.value))
		if (upload7ShowList.value.length > 0) {
			upload7ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload8List.value = data.reviewRevisedFileList
		upload8ShowList.value = JSON.parse(JSON.stringify(upload8List.value))
		if (upload8ShowList.value.length > 0) {
			upload8ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
		upload9List.value = data.reviewProposalFormFileList
		upload9ShowList.value = JSON.parse(JSON.stringify(upload9List.value))
		if (upload9ShowList.value.length > 0) {
			upload9ShowList.value.forEach((i: any) => {
				i.name = i.fileRealName + '.' + i.fileExtName
			})
		}
	})
}

const getResultDetail = () => {
	getResult({
		id: props.editId
	}).then(res => {
		let data = res.data
		resultDetail.value = data
	})
}

const standardDetail = (row: any) => {
	sId.value = row.projectId
	showPDialog.value = true
}

const closeModal = () => {
	emit('update:modelValue', false)
}

const handleClick = (tab: TabsPaneContext, event: Event) => {
	// console.log(tab, event)
}

const getStandardInfo = (data: any) => {
	standardInfo.value = data
	baseForm.value.standardReviewList.projectInfoId = data.projectId
	baseForm.value.standardReviewList.progressId = data.progressId
}

const handleEditReviewPerson = (e: ReviewPerson, i: number) => {
	showAddReviewPerson.value = true
	e.index = i
	reviewPersonInfo.value = e
}

const handleDeleteReviewPerson = (i: number) => {
	ElMessageBox.confirm('确定要删除吗?', '提示', {
		confirmButtonText: '删除',
		cancelButtonText: '取消',
		type: 'warning'
	}).then(() => {
		reviewPersonList.value.splice(i, 1)
	})
}

const submitReviewPerson = (e: ReviewPerson) => {
	showAddReviewPerson.value = false
	const index = e.index ?? -1
	if (index > -1) {
		reviewPersonList.value[index] = e
	} else {
		reviewPersonList.value.push({ ...e })
	}
}

const closeReviewPersonDialog = () => {
	reviewPersonInfo.value = {
		reviewName: '',
		reviewCompany: '',
		reviewProfession: '',
		reviewTel: '',
		reviewTitle: '',
		index: -1
	}
}

const handleUploadPdfPreview = (ruploadFile: any) => {
	if (ruploadFile.systemFileName) {
		filePreviewByName(ruploadFile.systemFileName).then(res => {
			window.open(res.data.url)
		})
	} else {
		filePreviewByName(ruploadFile?.response.data.systemFileName).then(res => {
			window.open(res.data.url)
		})
	}
}

const handleUploadSuccess = (index: number) => {
	return (response, file, fileList) => {
		if (response.code == '200') {
			const uploadLists = [upload1List, upload2List, upload3List, upload4List, upload5List, upload6List, upload7List, upload8List, upload9List]
			if (index >= 1 && index <= 9) {
				uploadLists[index - 1].value.push(response.data)
			}
			// if (index == 9) {
			// 	saveTemp(2)
			// }
		} else {
			handleUploadError(index)
		}
	}
}

const handleUploadError = (index: number) => {
	return (error: Error, uploadFile: UploadRawFile) => {
		ElMessage.error(error.message)
		const uploadShowLists = [
			upload1ShowList,
			upload2ShowList,
			upload3ShowList,
			upload4ShowList,
			upload5ShowList,
			upload6ShowList,
			upload7ShowList,
			upload8ShowList,
			upload9ShowList
		]
		if (index >= 1 && index <= 9) {
			uploadShowLists[index - 1].value = uploadShowLists[index - 1].value.filter((item: UploadRawFile) => item.uid !== uploadFile.uid)
		}
	}
}

const handleUploadRemove = (index: number) => {
	return (uploadFile: any) => {
		const uploadLists = [upload1List, upload2List, upload3List, upload4List, upload5List, upload6List, upload7List, upload8List, upload9List]
		if (index >= 1 && index <= 9) {
			const id = uploadFile.response ? uploadFile.response.data.id : uploadFile.id
			uploadLists[index - 1].value = uploadLists[index - 1].value.filter((item: any) => item.id !== id)
		}
	}
}

const setForm = () => {
	baseForm.value.promotersSessionList = upload1List.value
	baseForm.value.newsMediaReportList = upload2List.value
	baseForm.value.promotionalPlanList = upload3List.value
	baseForm.value.adoptTechnologyList = upload4List.value
	baseForm.value.winningAwardsList = upload5List.value
	baseForm.value.quotedPoliciesList = upload6List.value
	baseForm.value.quotedOtherStandardList = upload7List.value
	baseForm.value.reviewRevisedList = upload8List.value
	baseForm.value.reviewProposalFormList = upload9List.value
	const cleanedReviewPersonList = reviewPersonList.value.map(({ index, ...rest }) => rest)
	baseForm.value.standardReviewPersonList = cleanedReviewPersonList
	delete (baseForm.value as AddReview).previousVersions
}

const submitSave = () => {
	if (!standardInfo.value?.projectId) {
		return ElMessage.error('请选择项目标准!')
	}
	setForm()
	reviewAdd(baseForm.value).then(res => {
		ElMessage.success('操作成功！')
		baseFormRef.value?.resetFields()
		emit('submit-success')
	})
}

const saveTemp = (type: number) => {
	setForm()
	reviewUpdate(baseForm.value).then(res => {
		ElMessage({
			type: 'success',
			message: '保存成功',
			duration: 5000
		})
		if (type == 1) {
			emit('submit-success')
		}
	})
}

const submitForm = async (formEl: FormInstance | undefined) => {
	if (!formEl) {
		return
	}
	if (!standardInfo.value?.projectId) {
		if (activeName.value != 'base') {
			activeName.value = 'base'
		}
		return ElMessage.error('请选择项目标准!')
	}
	await formEl.validate((valid, fields) => {
		if (valid) {
			if (reviewPersonList.value.length < 5) {
				ElMessage.error('请至少填写5位审核人员！')
				if (activeName.value != 'table') {
					activeName.value = 'table'
				}
				return
			}
			if (baseForm.value.standardReviewImplementation.selfReviewConclusion == '3') {
				if (upload8List.value.length == 0) {
					ElMessage.error('请上传承诺书')
					scrollToInvalidField('请上传承诺书')
					return
				}
			}
			setForm()
			reviewSave(baseForm.value).then(res => {
				ElMessage.success('操作成功！')
				baseFormRef.value?.resetFields()
				emit('submit-success', res.data)
			})
		} else {
			if (!fields) {
				return
			}
			const firstErrorField = Object.keys(fields)[0]
			if (firstErrorField.startsWith('standardReviewList.')) {
				activeName.value = 'base'
				return
			}
			if (firstErrorField.startsWith('standardReviewImplementation.')) {
				activeName.value = 'table'
			}
			if (fields[firstErrorField]) {
				const msg = fields[firstErrorField][0].message
				scrollToInvalidField(msg)
			}
		}
	})
}

const scrollToInvalidField = (message: string) => {
	nextTick(() => {
		const formEl = baseFormRef.value?.$el

		// 1. 尝试匹配 label 文本
		const labels = formEl?.querySelectorAll('.el-form-item__error')
		let targetLabel: HTMLElement | null = null

		labels?.forEach((label: HTMLElement) => {
			if (label.textContent?.includes(message)) {
				targetLabel = label
			}
		})
		// 2. 如果找到 label，定位到对应的表单项
		if (targetLabel) {
			const formItem = targetLabel.closest('.el-form-item')
			const inputEl = formItem?.querySelector('.el-input, .el-select, .el-textarea')

			if (inputEl) {
				inputEl.scrollIntoView({ behavior: 'smooth', block: 'center' })
				inputEl.classList.add('highlight-field')
				setTimeout(() => inputEl?.classList.remove('highlight-field'), 2000)
				return
			}
		}

		// 3. 如果未匹配 label，尝试匹配 placeholder
		const inputs = formEl?.querySelectorAll('input, textarea, select')
		inputs?.forEach((input: HTMLInputElement) => {
			if (input.placeholder?.includes(message)) {
				input.scrollIntoView({ behavior: 'smooth', block: 'center' })
				input.classList.add('highlight-field')
				setTimeout(() => input.classList.remove('highlight-field'), 2000)
			}
		})
	})
}
</script>
<style lang="scss" scoped>
.tabs :deep(.el-tabs__nav-wrap) {
	display: flex;
	justify-content: center;
	margin-top: 10px;
}

.content {
	.add-unit {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 10px 0;

		.tit {
			font-size: 14px;
			color: #333;
			padding-top: 8px;

			span {
				color: red;
				margin-left: 5px;
			}
		}
	}

	.zhuguan {
		.menu {
			display: flex;
			position: relative;
			z-index: 9;

			.item {
				width: 122px;
				height: 38px;
				line-height: 38px;
				border-radius: 10px 10px 0 0;
				border-top: solid 1px #eee;
				border-left: solid 1px #eee;
				border-right: solid 1px #eee;
				text-align: center;
				cursor: pointer;
				margin-right: 10px;
				background-color: #f2f2f2;

				&.active {
					background-color: #fff;
					color: #1491ff;
				}
			}
		}
	}

	.box {
		padding: 5px 20px 20px;
		border: solid 1px #eee;
		position: relative;
		z-index: 1;
		margin-top: -1px;
		margin-bottom: 20px;

		.row {
			display: flex;
			margin-top: 15px;

			.label {
				min-width: 90px;
				color: #999;
			}
		}
	}

	.box1 {
		border: solid 1px #eee;
		margin-bottom: 20px;

		.title {
			height: 48px;
			line-height: 48px;
			background-color: #f2f2f2;
			text-indent: 16px;
		}

		.box-content {
			padding: 5px 20px 20px;

			.row {
				display: flex;
				margin-top: 15px;

				.label {
					min-width: 90px;
					color: #999;
				}
			}

			.result {
				text-align: center;
				font-size: 20px;
				color: #1491ff;
				padding: 30px 0 20px;
			}
		}
	}
}

.dialog-foot {
	display: flex;
	justify-content: center;
	margin-bottom: 10px;
	padding-bottom: 20px;
}

.table {
	border: solid 1px #eee;
	margin-bottom: 15px;

	.table-title {
		background-color: #f2f2f2;
		height: 48px;
		line-height: 48px;
		font-size: 14px;
		color: #333;
		text-indent: 16px;
	}

	.table-content {
		padding: 16px;

		.upload {
			display: flex;
			align-items: center;
		}
	}
}

.highlight-field {
	animation: highlight 1.5s;
}

@keyframes highlight {
	0% {
		background-color: var(--el-color-danger-light-9);
	}

	100% {
		background-color: transparent;
	}
}
</style>
